#!/bin/sh
# Example: database username databasename
PREFIX="con_"
USERNAME="$1"
DATABASE="${PREFIX}$2"
PASSWORD=$(echo $RANDOM|md5sum); PASSWORD=${PASSWORD:2:9};

# What log file to produce?
DBSCRIPTS="/tmp/${DATABASE}.log"

echo \#DROP DATABASE IF EXISTS \`${DATABASE}\`\; > ${DBSCRIPTS}
echo CREATE DATABASE \`${DATABASE}\` CHARACTER SET utf8 COLLATE utf8_general_ci\; >> ${DBSCRIPTS}
echo GRANT ALL ON \`${DATABASE}\`.* TO \'${USERNAME}\'@\'localhost\' IDENTIFIED BY \'${PASSWORD}\'\; >> ${DBSCRIPTS}
echo GRANT ALL ON \`${DATABASE}\`.* TO \'${USERNAME}\'@\'%\' IDENTIFIED BY \'${PASSWORD}\'\; >> ${DBSCRIPTS}
echo FLUSH PRIVILEGES\; >> ${DBSCRIPTS}
cat ${DBSCRIPTS}

/opt/lampp/bin/mysql -uroot -pd47tvyjp < ${DBSCRIPTS}
